package keke;

import java.util.ArrayList;
import java.util.Scanner;

interface GeneralStack<T>{
	public T push(T item);
	public T pop(); 
	public T peek(); 
	public boolean empty();
	public int size();
}
class ArrayListGeneralStack<T> implements GeneralStack<T>{
	public ArrayList<T>list;
	public ArrayListGeneralStack(){
		list = new ArrayList<T>();
	}
	
	@Override
	public String toString() {
		return list.toString();
	}
	@Override
	public T push(T item) {
		if(item==null)
			return null;
		list.add(item);
			return item;
	}
	@Override
	public T pop() {
		if(list.isEmpty())
			return null;
		return list.remove(list.size()-1);
			
	}
	@Override
	public T peek() {
		if(list.isEmpty())
			return null;
		return list.get(list.size()-1);
	}
	@Override
	public boolean empty() {
		return list.isEmpty();
	}
	@Override
	public int size() {
		return list.size();
	}
}
class Car{
	private int id;
	private String name;
	public Car() {
		this.id=id;
		this.name=name;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Override
	public String toString() {
		return "Car [id=" + id + ", name=" + name + "]";
	}
	
}
public class Main0505 {
	public static <T> void main(String[] args) {
        Scanner in=new Scanner(System.in);
        while(in.hasNext()){
        	String str=in.next();
	        if(str.equals("quit"))
	        	break;
	        else if(str.equals("Integer")){
	        	System.out.println("Integer Test");
	        	int m=in.nextInt();
	 	        int n=in.nextInt();
	 	        int sum=0;
	 	        ArrayListGeneralStack<Integer> stack=new ArrayListGeneralStack<Integer>();
	        	for(int i=0;i<m;i++)
	        		System.out.println("push:"+stack.push(in.nextInt()));
	        	for(int i=0;i<n;i++)
	        		System.out.println("pop:"+stack.pop());
	        	System.out.println(stack);
	        	while (!stack.empty()){
	        		sum=sum+stack.peek();
	        		stack.pop();
	        	}
	        	System.out.println("sum="+sum);
	        	System.out.println(stack.getClass().getInterfaces()[0]);
	        }
	        else if(str.equals("Double")){
	        	System.out.println("Double Test");
	        	int m=in.nextInt();
	 	        int n=in.nextInt();
	 	        double sum=0.0;
	 	        ArrayListGeneralStack<Double> stack=new ArrayListGeneralStack<Double>();
	        	for(int i=0;i<m;i++)
	        		System.out.println("push:"+stack.push(in.nextDouble()));
	        	for(int i=0;i<n;i++)
	        		System.out.println("pop:"+stack.pop());
	        	System.out.println(stack);
	        	while (!stack.empty()){
	        		sum=sum+stack.peek();
	        		stack.pop();
	        	}
	        	System.out.println("sum="+sum);
	        	System.out.println(stack.getClass().getInterfaces()[0]);
	        }
	        else if(str.equals("Car")){
	        	System.out.println("Car Test");
	        	int m=in.nextInt();
	 	        int n=in.nextInt();
	 	        ArrayListGeneralStack<Car> stack=new ArrayListGeneralStack<Car>();
	        	for(int i=0;i<m;i++){
	        		Car car=new Car();
	        		car.setId(in.nextInt());
	        		car.setName(in.next());
	        		System.out.println("push:"+stack.push(car).toString());
	        	}
	        	for(int i=0;i<n;i++)
	        		System.out.println("pop:"+stack.pop().toString());
	        	System.out.println(stack);
	        	while (!stack.empty()){
	        		System.out.println(stack.peek().getName());
	        		stack.pop();
	        	}
	        	System.out.println(stack.getClass().getInterfaces()[0]);
	        } 
	     }
	}
}